package cn.shengchao.examstar.share.domain.valobj;

import com.quaint.poster.annotation.PosterBackground;
import com.quaint.poster.annotation.PosterImageCss;
import com.quaint.poster.core.abst.AbstractDefaultPoster;
import com.quaint.poster.core.impl.PosterDefaultImpl;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Tolerate;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.net.URL;

@EqualsAndHashCode(callSuper = true)
@Data
@Builder
public class SamplePoster extends AbstractDefaultPoster {
    /**
     * 背景图
     */
    @PosterBackground(width = 1500,height = 3280)
    private BufferedImage backgroundImage;

    /**
     * 主图
     */
    @PosterImageCss(position = {955,2735},width = 360,height = 360)
    private BufferedImage mainImage;

    @Tolerate
    public SamplePoster() {}

    public static void main(String[] args) throws Exception{

        // 测试注解, 这里读取图片如果不成功，请查看target 或者 out 目录下是否加载了资源。 如需使用，请引入spring core依赖
        BufferedImage background = ImageIO.read(new URL("http://exam-star.oss-cn-beijing.aliyuncs.com/2025/4/22/680751dfe4b082c9d5b46095.png"));
        BufferedImage head = ImageIO.read(new URL("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2Ff26f5ed0d000c3413c9a4250f2c22bcb86a9494e2b2a-Gw0bYT_fw658&refer=http%3A%2F%2Fhbimg.b0.upaiyun.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1643361653&t=8a75ad80a91a83bff0cf64677e940207"));
        SamplePoster poster = SamplePoster.builder()
                .backgroundImage(background)
                .mainImage(head)
                .build();
        PosterDefaultImpl<SamplePoster> impl = new PosterDefaultImpl<>();
        BufferedImage test = impl.annotationDrawPoster(poster).draw(null);
        ImageIO.write(test,"png",new FileOutputStream("annTest.png"));
    }
}
